package com.testing.class6.RoyPO;

import com.testing.common.AutoTools;
import com.testing.web.WebKeyword;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.IOException;

/**
 * @Classname ShopAdminPage
 * @Description 按page object 模式 整理成页面。
 * @Date 2022/10/12 20:06
 * @Created by 特斯汀Roy
 */
public class ShopAdminPage extends WebKeyword {

    private String adminUrl = "http://www.testingedu.com.cn:8000/index.php/Admin";

    public ShopAdminPage() {
        AutoTools.log.info("后台的添加测试开始了");
        openBrowser("chrome");
        visitWeb(adminUrl);
    }

    public ShopAdminPage(WebDriver driver){
        log.info("通过外部打开浏览器进行后台测试");
        setDriver(driver);
        visitWeb(adminUrl);
    }

    public void addGoods() {
        click("//a[text()='商城']");
        //切换Iframe
        switchFrame("workspace");
        //添加商品
        click("//span[text()='添加商品']");
        saveDateParam("随机商品", "VIP13测试商品", "ddHHmmss");
        input("//input[@name='goods_name']", "{随机商品}");
        click("//select[@id='cat_id']");
        click("//option[contains(text(),'服饰')][@value='12']");
        halt("0.5");
        select("//select[@id='cat_id_2']", "{value}23");
        halt("0.5");
        select("//select[@id='cat_id_3']", "{text}休闲裤");
        input("//input[@name='shop_price']", "300");
        input("//input[@name='market_price']", "500");
        //文件上传
        click("//input[contains(@title,'点击前方预览图可查看大图')]");
        switchFrame("//iframe[contains(@id,'layui')]");
        input("//div[text()='点击选择文件']/following-sibling::div[@id]/input", "E:\\QSwork\\素材\\悠米微信 .png");
        halt("1");
        click("//div[text()='确定使用']");
        switchFrame("workspace");
        //选择是 包邮
        click("//label[text()='是' and @id]");
        click("//a[text()='确认提交']");
        //断言标准是第一个元素的商品名称是VIP13测试商品
        assertEleText("//div[@id='flexigrid']//tr[1]/td[4]", "{随机商品}");
        assertDbExists("select * from tp_goods where goods_name = '{随机商品}'");
        halt("3");
        log.info("参数存储map的内容"+paramMap);
        closeBrowser();
    }

    public void loginAdmin(String user,String pwd) {
        input("//input[@name='username']", user);
        input("//input[@name='password']", pwd);
        input("//input[@name='vertify']", "1");
        click("//input[@value='登录']");
    }

}
